import CacheUtil from "@/utils/CacheUtil";
import axios from "axios";

function RequestUtil (){}

 RequestUtil.sendCacheableRequest = async function (key, uri) {
    // console.log(key, uri)
    // 查缓存
    if (CacheUtil.exists(key)) {
        console.log(`Cache Get ${key}.`)
        return CacheUtil.getCache(key)
    }
    console.log(axios)
    axios.get(`/api${uri}`).then(res => {
        console.log(`Send Request ${key}.`)
        let data = res.data.data;
        CacheUtil.setCache(key, data)
        return data
    })
}

RequestUtil.listToMap = function (list){
    let ret = {};
    list.forEach(item => {
        ret[item.id] = item.name;
    })
    return ret;
}







export default RequestUtil